package com.wwdx.controller.admin;

import com.wwdx.controller.base.BaseController;
import com.wwdx.model.*;
import com.wwdx.model.dto.ResultBean;
import com.wwdx.utils.ConstantHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * 统计
 * @author liguoliang
 * @date 2017/11/23
 */
@Controller
@RequestMapping("/system/statistics")
public class StatisticsController extends BaseController{

    @RequestMapping("/index")
    public ModelAndView statistics() {
        return new ModelAndView();
    }
    
    /**
     * 收入统计列表
     */
    @RequestMapping("/income")
    @ResponseBody
    public Map<String,Object> income(WwdxInComeModel model,
                           @RequestParam(value = "page", defaultValue = "1") Integer page,
                           @RequestParam(value = "rows",defaultValue = "10") Integer rows){
        
        Map<String,Object> map = new HashMap<>(2);
        map.put("total",  statisticsInComeService.selectModelCount(model));
        map.put("rows",  statisticsInComeService.selectModelList(model,page,rows));
        return map;
    }

    /**
     * 发送邮件
     */
    @RequestMapping("/income/send")
    @ResponseBody
    public ResultBean incomesend(String email){
        return renderSuccess(taskService.sendEmail(ConstantHolder.Constant.PRE_WWDXINCOME,email,"收入统计信息"));
    }

    /**
     * 页面点击量列表
     */
    @RequestMapping("/page")
    @ResponseBody
    public Map<String,Object> page(WwdxPageStatisticsModel model,
                                   @RequestParam(value = "page", defaultValue = "1") Integer page,
                                   @RequestParam(value = "rows",defaultValue = "10") Integer rows){

        Map<String,Object> map = new HashMap<>(2);
        map.put("total",  wwdxPageStatisticsService.selectModelCount(model));
        map.put("rows",  wwdxPageStatisticsService.selectModelList(model,page,rows));
        return map;
    }

    /**
     * 赠一得一按渠道统计
     */
    @RequestMapping("/giveonechannel")
    @ResponseBody
    public Map<String,Object> giveonechannel(WwdxGiveoneChannelModel model,
                                             @RequestParam(value = "page", defaultValue = "1") Integer page,
                                             @RequestParam(value = "rows",defaultValue = "10") Integer rows){

        Map<String,Object> map = new HashMap<>(2);
        map.put("total",  wwdxGiveoneChannelService.selectModelCount(model));
        map.put("rows",  wwdxGiveoneChannelService.selectModelList(model,page,rows));
        return map;
    }

    /**
     * 赠一得一按书籍统计
     */
    @RequestMapping("/giveonebook")
    @ResponseBody
    public Map<String,Object> giveonebook(WwdxGiveoneBookModel model,
                                          @RequestParam(value = "page", defaultValue = "1") Integer page,
                                          @RequestParam(value = "rows",defaultValue = "10") Integer rows){

        Map<String,Object> map = new HashMap<>(2);
        map.put("total",  wwdxGiveoneBookService.selectModelCount(model));
        map.put("rows",  wwdxGiveoneBookService.selectModelList(model,page,rows));
        return map;
    }

    /**
     * 赠一得一按用户统计
     */
    @RequestMapping("/giveoneuser")
    @ResponseBody
    public Map<String,Object> giveoneuser(WwdxGiveoneUserModel model,
                                          @RequestParam(value = "page", defaultValue = "1") Integer page,
                                          @RequestParam(value = "rows",defaultValue = "10") Integer rows){

        Map<String,Object> map = new HashMap<>(2);
        map.put("total",  wwdxGiveoneUserService.selectModelCount(model));
        map.put("rows",  wwdxGiveoneUserService.selectModelList(model,page,rows));
        return map;
    }

    /**
     * 早读听书打卡统计
     */
    @RequestMapping("/cardreading")
    @ResponseBody
    public Map<String,Object> cardreading(WwdxCardModel model,
                                          @RequestParam(value = "page", defaultValue = "1") Integer page,
                                          @RequestParam(value = "rows",defaultValue = "10") Integer rows){

        Map<String,Object> map = new HashMap<>(2);
        map.put("total",  wwdxCardService.selectModelCount(model));
        map.put("rows",  wwdxCardService.selectModelList(model,page,rows));
        return map;
    }
}